<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/includes.jsp"%>
<%@ include file="/WEB-INF/view/header.jsp"%>


<div class="easyui-layout" style="width:700px;height:350px;margin-right:auto;margin-left:auto;">
		<div data-options="region:'north',border:false" style="height:50px"></div>
		<div data-options="region:'south',border:false" style="height:50px;"></div>
	
		<div data-options="region:'center',title:'CMP Console System'">
			<div style="padding:50px 0 10px 200px">
			
			<div id="showMsg" style="color: red"></div>
			
	    <form id="loginForm" method="post" action="/login">
	    	<table>
	    		<tr>
	    			<td>Name:</td>
	    			<td><input class="easyui-validatebox" type="text" name="username" data-options="required:true"></input></td>
	    		</tr>
	    		<tr>
	    			<td>Password:</td>
	    			<td><input class="easyui-validatebox" type="password" name="password" data-options="required:true"></input></td>
	    		</tr>
	    		<tr>
	    			<td></td>
	    			<td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="login()">Login</a>
	    			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">Clear</a></td>
	    		</tr>
	    	</table>
	    </form>
	    </div>
		</div>
	</div>

<script type="text/javascript">


	if (window != top) {
		top.location.href = location.href;
	}

	document.onkeydown = function(e) {
		var event = e || window.event;
		var code = event.keyCode || event.which || event.charCode;
		if (code == 13) {
			login();
		}
	}

	function clearForm() {
		$('#loginForm').form('clear');
	}

	function login() {
		var flag = $('#loginForm').form('validate');
		if (flag) {
			$("#showMsg").html("Loging in, please wait...");
			$
					.ajax({
						type : "POST", //post提交方式默认是get
						url : "loginSubmit",
						data : $("#loginForm").serialize(), //序列化 
						error : function(request) { // 设置表单提交出错                 
							$("#showMsg").html(request); //登录错误提示信息
						},
						success : function(data) {
							alert("Success and data is="+data.loginstatus);
							//alert("Success and data is="+data.loginmsg);
							if ("Success" == data.loginstatus) {
								// 登陆后跳转到referrer链接,或者跳转到desktop页面.
								if (document.referrer
										.indexOf('/pvconsole/orderendcomplete') != -1) {
									document.location = document.referrer;
								} else {
									document.location = "desktop";
								}
							} else if ("NOACCESS" == data.loginstatus) {
								$("#showMsg")
										.html(
												data.loginmsg
														+ 'To gain access,please contact with <a href="mailto:ccs-prov-dev@cisco.com">site admin</a>.');
							} else {
								$("#showMsg").html(data.loginmsg);
							}
						}
					});
		}
	}
</script>
<%@ include file="/WEB-INF/view/footer.jsp"%>